<?php

namespace app\controller\en;

use think\facade\View;

use app\controller\en\Base;
use app\model\ArticleEn;
use app\model\ProductsWireEn;
use app\model\ProductsSurfaceEn;
use app\model\ProductsWearPlateEn;
use app\model\Industry;

class Index extends Base
{
    public function index()
    {
        return View::fetch();
    }

    public function about()
    {
        return View::fetch();
    }

    public function development()
    {
        return View::fetch();
    }

    public function honor()
    {
        return View::fetch();
    }

    public function factory()
    {
        return View::fetch();
    }

    public function contactus()
    {
        return View::fetch();
    }

    public function search($key = "")
    {
        $key = $this->request->has('key') ? (string)$this->request->param('key') : '';

        $news_list = $product_list = $industry_list = null;

        if ($key != '') {
            $news_list = ArticleEn::where('title|keywords', 'LIKE', '%' . $key . '%')->where('status', 1)->field('id,cid,title,titlepic,username,summary,hits,sort,pubtime')->select();

            $product_list_wire       = ProductsWireEn::where('title|productstype', 'LIKE', '%' . $key . '%')->field('id, productstype,create_time')->select();
            $product_list_surface    = ProductsSurfaceEn::where('productstype', 'LIKE', '%' . $key . '%')->field('id, productstype,create_time')->select();
            $product_list_wear_plate = ProductsWearPlateEn::where('productstype', 'LIKE', '%' . $key . '%')->field('id, productstype,create_time')->select();

            $product_list = array_merge($product_list_wire->toArray(), $product_list_surface->toArray(), $product_list_wear_plate->toArray());

            $industry_list = Industry::where('title|keywords', 'LIKE', '%' . $key . '%')->field('id,title,titlepic,summary,create_time')->select();
        }

        return View::fetch('', [
            'key'              => $key,
            'news_list'     => $news_list,
            'product_list'  => $product_list,
            'industry_list' => $industry_list
        ]);
    }



    public function test()
    {
        return "this is test";
    }
}
